<template>
	<view class="bg-white">

		<uni-calendar :insert="true" :lunar="true" :start-date="'1949-10-01'" :end-date="'2099-12-30'" />

		<button type="primary" @click="goToListPage">to list</button>

		<button type="primary" @click="goToWallpaperPage">to wallpaper</button>

		<view class="text-[#f40]">当前定位信息：{{ location }}</view>
		<button type="primary" @click="scan">扫码</button>
	</view>

</template>

<script setup lang="ts">
	// import {Request} from '@/utils/request';

	let location = ref('');

	onMounted(async () => {
		// const res = Request({
		//   url: '/api/map/weather/1?t=1723280172604'
		// });
		//
		// console.log(' =====', res);


		uni.getLocation({
			type: 'wgs84',
			success: (res) => {
				location.value = 'success res =====' + JSON.stringify(res);
			},
			fail: (res) => {
				location.value = 'fail res =====' + JSON.stringify(res);
			},
			// complete: (res) => {
			//   location.value = 'complete res =====' + res;
			// }
		});



		// 动态修改标题
		uni.showNavigationBarLoading()

		setTimeout(() => {
			uni.hideNavigationBarLoading()
			uni.setNavigationBarTitle({
				title: '新的标题'
			});
		}, 2000)
	});


	// 使用页面uni的生命周期
	onLoad((e) => {
		console.log('onLoad', e)
	})

	onReady(() => {
		console.log('onRead')
	})

	const goToListPage = () => {
		// uni.redirectTo()
		uni.navigateTo({
			url: '/pages/list/index'
		});
	};

	const goToWallpaperPage = () => {
		uni.navigateTo({
			url: '/pages/wallpaper/index'
		});
	}

	// H5不支持扫码
	const scan = () => {
		// uni.scanCode({
		//   success: function (res) {
		//     console.log('条码类型：' + res.scanType);
		//     console.log('条码内容：' + res.result);
		//   }
		// });
		uni.chooseImage({
			count: 1, //默认9
			sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
			sourceType: ['album', 'camera'], //从相册选择
			success: function (res) {
				console.log(JSON.stringify(res.tempFilePaths));
			}
		});
	}
</script>

<style lang="scss">
	.uni-margin-wrap {
		width: 100%;
	}

	.swiper {
		height: 400rpx;
	}

	.swiper-item {
		width: 100%;
		height: 400rpx
	}

	.grid-index-page {
		margin-top: 10rpx;
		margin-bottom: 10rpx;
	}
</style>